package com.rem.hutool.my11HttpUtil;

import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.HashMap;

/**
 * @Author Rem
 * @Date 2020-09-20
 */

public class HttpUtilDemo {

    public static void main(String[] args) {
        String loginInfo = login();
        JSONObject login = JSONUtil.parseObj(loginInfo);

        long file = HttpUtil.downloadFile("http://47.101.39.184:8184/sys/coupon/export?pageNum=1&pageSize=10&token=" + login.get("token"),
                "../../src/main/resources/static/卡券管理.xlsx");

    }

    private static void saveCoupn() {
        String loginInfo = login();
        JSONObject login = new JSONObject(loginInfo);

        JSONObject jsonObject = new JSONObject();
        jsonObject.putOpt("actionStatus", 1);
        jsonObject.putOpt("activity", "1,2");
        jsonObject.putOpt("addNum", 99999999);
        jsonObject.putOpt("description", "测试优惠券的描述");
        jsonObject.putOpt("goodsType", "1");
        jsonObject.putOpt("name", "测试优惠券");
        jsonObject.putOpt("reductionAmount", 5);
        jsonObject.putOpt("totalAmount", 32);
        jsonObject.putOpt("type", 1);
        String json = jsonObject.toString();


        String saveCoupn = HttpUtil.post("http://47.101.39.184:8184/sys/coupon/saveCoupon/?token=" + login.get("token"), json);
        System.err.println(saveCoupn);
    }


    private static String login() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("account", "admin");
        map.put("password", "bmhxt");
        return HttpUtil.get("http://47.101.39.184:8184/sys/admin/login", map);
    }
}
